#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

vector<int> findSubstring(string s, vector<string> &words)
{
    vector<int> v;
    unordered_map<string, int> hash1;
    unordered_map<string, int> hash2;
    for(auto& e : words)
    {
        hash1[e]++;
    }
    int len = words[0].size(), m = words.size();
    for (int i = 0; i < len;i++)
    {
        hash2.clear();
        for (int left = i, right = i, count = 0; right + len <= s.size();right += len)
        {
            string in = s.substr(right, len);
            hash2[in]++;
            if (hash1.count(in) && hash2[in] <= hash1[in])
                count++;
            if(right - left + 1 > m * len)
            {
                string out = s.substr(left, len);
                if(hash1.count(out) && hash2[out] <= hash1[out])
                    count--;
                hash2[out]--;
                left += len;
            }
            if(count == m)
            {
                v.push_back(left);
            }
        }
    }
    return v;
}
